class BangumisController < ApplicationController
  skip_before_filter :verify_authenticity_token
  #before_filter :correct_bili_name?, :limit_bili_users
  #layout "need_bili_name"

  def new
    @bangumi = Bangumi.new :bangumi_type_id => params[:bangumi_type_id]
  end

  def edit
    @bangumi = Bangumi.find params[:id]
  end

  def index
    @type = BangumiType.find params[:bangumi_type_id]
    @bangumis = Bangumi.all :conditions => ["bangumi_type_id = ?", params[:bangumi_type_id]]
  end

  def create
    bangumi = Bangumi.new params[:bangumi]
    bangumi.status = 0
    unless params[:avid].blank?
      work = Work.find_by_wid params[:avid]
      bangumi.pic_path = work.pic_path
    end
    bangumi.save!
    redirect_to :action => :index, :bangumi_type_id => bangumi.bangumi_type_id
  end

  def update
    bangumi = Bangumi.find params[:id]
    bangumi.update_attributes params[:bangumi]
    redirect_to :action => :index, :bangumi_type_id => bangumi.bangumi_type_id
  end
end
